package com.alex.space.commons.jdk.kit8;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author Alex
 *         Created by Alex on 2017/12/22.
 *         <p>
 *         Lambda
 */
public class LambdaDemo {

    static int outerStaticNum;
    static int outerNum;

    public static void run() {
        List<String> names = Arrays.asList("peter", "bob", "alex");

        // old
        Collections.sort(names, new Comparator<String>() {
            @Override
            public int compare(String a, String b) {
                return b.compareTo(a);
            }
        });

        // new
        Collections.sort(names, (String a, String b) -> {
            return b.compareTo(a);
        });

        names.sort((a, b) -> b.compareTo(a));

        // scope
        final int num = 1;
        Converter<Integer, String> stringConverter = (from) -> String.valueOf(from + num);
        stringConverter.convert(2);

        Converter<Integer, String> stringConverter1 = (from) -> {
            outerNum = 23;
            return String.valueOf(from);
        };
        Converter<Integer, String> stringConverter2 = (from) -> {
            outerStaticNum = 72;
            return String.valueOf(from);
        };
    }
}
